package com.tvunetworks.center.device.service.impl;


import com.tvunetworks.center.common.model.UserCondition;
import com.tvunetworks.center.common.util.MyUtil;
import com.tvunetworks.center.device.mapper.UserConditionMapper;
import com.tvunetworks.center.device.service.UserConditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @program:
 * @description:
 * @author HenryChen
 * @create: 7/26/2019 4:02 PM
 **/
@Service
public class UserConditionServiceImpl implements UserConditionService {
    @Autowired
    private UserConditionMapper userConditionMapper;
    @Override
    public void updataUserCondition(UserCondition userCondition) throws Exception {
        UserCondition uc =  this.selectUserConditionByCondition(userCondition.getCondition());
        if(uc == null){
            userCondition.setId(MyUtil.getUUID());
            userCondition.setCreatTime(System.currentTimeMillis());
            userCondition.setUpdateTime(System.currentTimeMillis());
            userCondition.setDeleteFlag(0);
            userConditionMapper.insert(userCondition);
        }else {
            userCondition.setId(uc.getId());
            userCondition.setUpdateTime(System.currentTimeMillis());
            userConditionMapper.updateByPrimaryKeySelective(userCondition);
        }
    }

    @Override
    public UserCondition selectUserConditionByCondition(String condition) throws Exception {
        UserCondition userCondition = new UserCondition();
        userCondition.setCondition(condition);
        return userConditionMapper.selectOne(userCondition);
    }

    @Override
    public List<String> getConditionByUserId(String uid) throws Exception {
        return userConditionMapper.getConditionByUserId(uid);
    }
}
